home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dbg / sun3.md / dbgTrap.s < prev    next >
Text File  |  1990-09-23  |  5KB  |  176 lines

  1. |* dbgTrap.s -
  2. |*
  3. |*     Contains the routine which will initialize things and call the main
  4. |*     debugger routine.
  5. |*
  6. |* Copyright (C) 1985 Regents of the University of California
  7. |* All rights reserved.
  8. |*
  9.  
  10.     .data
  11.     .asciz "$Header: /sprite/src/kernel/dbg/sun3.md/RCS/dbgTrap.s,v 9.1 90/02/12 11:11:18 rab Exp $ SPRITE (Berkeley)"
  12.     .even
  13.     .text
  14.  
  15. #include "machConst.h"
  16. #include "dbgAsm.h"
  17. #include "machAsmDefs.h"
  18.  
  19. | ***********************************************************************
  20. |
  21. | _Dbg_Trap --
  22. |
  23. |     Call the main debugger routine.  There is a division of labor between
  24. |     the original trap handler that called us, this routine and the main 
  25. |     debugger routine.  The trap handler has put the stack in the following
  26. |     state:
  27. |
  28. |        ------------
  29. |        |          |    Trap type (4 bytes)
  30. |        ------------
  31. |        |          |    Bus error register (4 bytes)
  32. |        ------------
  33. |        |          |    Status register (2 bytes)
  34. |        ------------
  35. |        |          |     Program counter where trap occured (4 bytes)
  36. |        ------------
  37. |        |       |    Vector offset register (2 bytes)
  38. |        ------------
  39. |        |          |    Bus error stuff if a bus error.
  40. |        ------------
  41. |
  42. |     The bottom part of the stack (status register, PC, VOR, Bus error
  43. |     stuff) is the exception stack which was created by the 68000 when
  44. |     the trap occured. This routine is responsible for changing the 
  45. |     function codes to user data, changing the context to
  46. |     the kernel context, locking out interrupts, and saving registers.  It
  47. |     then calls the |     main debugger routine.  The main debugger routine
  48. |     is responsible for dealing with the stack.  When this routine is 
  49. |     returned to it is responsible for restoring the context, function codes, 
  50. |     and registers.  The PC and status register are restored automatically 
  51. |     when this routine does its return from exception.
  52. |
  53. |     This debugger code is non reentrant.  Therefore before this routine 
  54. |     will do the things listed above it checks to make sure that the 
  55. |     debugger is not already active.  If it is then this routine will
  56. |     restore registers, set a flag to reenter the debugger as soon as it
  57. |     returns, and return.  If it isn't active it marks itself as active and
  58. |     does the above.
  59. |
  60. | Return value:
  61. |     None.
  62. |
  63. | Side effects:
  64. |     The flag dbgInDebugger is modified to indicate that the debugger is 
  65. |     active, dbgTermReason is modified to indicate why we are in the debugger,
  66. |     and dbgMonPC is cleared if it is set.
  67. |
  68.  
  69.     .text
  70.     .globl    _Dbg_Trap
  71. _Dbg_Trap:
  72.     movw    #MACH_SR_HIGHPRIO,sr         | Lock out interrupts
  73.  
  74. | Check to see if we are already in the debugger.  If we are then we can't
  75. | enter it again so complain, mark an interrupt as pending, 
  76. | and return.
  77.  
  78.     tstl    _dbgInDebugger            | This flag should not be set.
  79.     beqs    2f                | If it isn't then go ahead
  80.  
  81.     jsr    _DbgComplain            | If it is set then complain.
  82.  
  83. | If _dbgMonPC is non-zero then it contains the real PC
  84.  
  85.     tstl    _dbgMonPC            | Check if monitor PC is set.
  86.     beqs    1f                | If zero don't do anything
  87.                         | Move the PC onto the stack
  88.     movl    _dbgMonPC, sp@(MACH_PC_OFFSET + MACH_TRAP_INFO_SIZE)
  89.     clrl    _dbgMonPC            | Clear out the PC for next time
  90. 1:
  91.     movl    #1, _dbgIntPending        | We leave an interrupt pending
  92.                         | marker.
  93.     addl    #MACH_TRAP_INFO_SIZE, sp    | Blow off trap type and bus
  94.                         |    error register
  95.     rte                    | Return to where called from.
  96.  
  97. 2:
  98.     movl    #1, _dbgInDebugger        | Set the flag to indicate
  99.                         | that we are in the debugger.
  100.  
  101. | If _dbgMonPC is non-zero then it contains the real PC
  102.  
  103.     tstl    _dbgMonPC
  104.     beqs    3f                | If zero don't do anything
  105.  
  106.                         | Move the PC onto the stack
  107.     movl    _dbgMonPC, sp@(MACH_PC_OFFSET + MACH_TRAP_INFO_SIZE) 
  108.     clrl    _dbgMonPC            | Clear out the PC for next time
  109.  
  110.                         | Also in this case this was
  111.                         | an interrupt, not a trap
  112.     movl    #DBG_INTERRUPT_SIG, _dbgTermReason    
  113.     bras    4f
  114. 3:
  115.  
  116. | Otherwise, the reason is some sort of trap.  We will determine the reason in
  117. | the main debugger routine.
  118.  
  119.     movl    #DBG_NO_REASON_SIG, _dbgTermReason
  120.  
  121. 4:
  122.     moveml    #0xffff, sp@-        | Save all of the gprs
  123.  
  124. | Save the function code registers.
  125.  
  126.     movc    sfc, d0
  127.     movl    d0, _dbgSfcReg
  128.     movc    dfc, d0
  129.     movl    d0, _dbgDfcReg
  130.  
  131. | Save user and kernel context registers
  132.  
  133.         jsr     _VmMachGetUserContext
  134.     movl    d0, _dbgUserContext
  135.         jsr     _VmMachGetKernelContext
  136.     movl    d0, _dbgKernelContext
  137.  
  138. | Call the debugger routine
  139.  
  140. callDbg:
  141.  
  142.     subl    #DBG_STACK_HOLE, sp     | Put a hole in the stack so that 
  143.                     | kdbx can play with its concept of 
  144.                     | the stack.
  145.  
  146.     jsr    _Dbg_Main        | Call the debugger
  147.  
  148.     movl    _dbgSavedSP, sp        | Set the sp pointer to the right
  149.                     | value so it can get at the saved regs
  150.  
  151. | See if we have an interrupt pending.  If so then check for exception type
  152. | of bus error or address error.  If one of these then ignore the interrupt.
  153. | Otherwise give our reason as interrupted and go back in.
  154.  
  155.     tstl    _dbgIntPending
  156.     beqs    5f
  157.     clrl    _dbgIntPending
  158.     cmpl    #MACH_BUS_ERROR, sp@
  159.     beqs    5f
  160.     cmpl    #MACH_ADDRESS_ERROR, sp@
  161.     beqs    5f
  162.     movl    #DBG_INTERRUPT_SIG, _dbgTermReason
  163.     bras    callDbg
  164.  
  165. 5:
  166.     moveml    sp@+, #0xffff        | Restore all registers.
  167.     addl    #MACH_TRAP_INFO_SIZE, sp | Blow off bus error reg and
  168.                      |   and trap type.
  169.  
  170. | Return from the exception
  171.  
  172.     clrl    _dbgInDebugger        | Clear the flag which indicates
  173.                     | that we are in the debugger.
  174.  
  175.     rte
  176.